from matplotlib import pyplot as plt
import random as rd
import numpy as np

# histogram
height=[168,155,182,170,173,161,155,173,176,181,166,172,170]
bins=range(150,191,5)
plt.hist(height,bins=bins)
plt.show()
# bar chart
classes=['class 1','class 2','class 3']
scores=[70,80,60]
plt.bar(classes,scores)
plt.show()
# line chart
height=[157,160,162,163,167,170,173,175,174,179,182,182,182,182,183]
year=range(2005,2020)
plt.plot(year,height)
plt.show()
# pie chart
labels=['house','diet','transport','education']
data=[8000,2000,2000,3000]
plt.pie(data,labels=labels,autopct='%1.1f%%')
plt.show()
# scatter diagram
data=[[18.9,10.4],[21.3,8.7],[19.5,11.6],[20.5,9.7],[19.9,9.4],
      [22.3,11],[21.4,10.6],[9,9.4],[10.4,9],[9.3,11.3],
      [11.6,8.5],[11.8,10.4],[10.3,10],[8.7,9.5],[14.3,17.2],
      [14.1,15.5],[14,16.5],[16.5,17.7],[15.1,17.3],[16.4,15],[15.7,18]]
X=[ item[0] for item in data ]
Y=[ item[1] for item in data ]
plt.scatter(X,Y)
plt.title('Supermarket Goods Price and Sales')
plt.xlabel('Price(yuan)')
plt.ylabel('Sales(number)')
plt.text(16,16,'Toothpaste')
plt.text(10,12,'Tissue')
plt.text(20,10,'Liquid Soap')
plt.show()
# box diagram
data=[]
for i in range(30):
    data.append(rd.randrange(101))
plt.boxplot(data)
plt.show()
# polar diagram
r=[1,2,3,4,5]
theta=[0.0,np.radians(90),np.radians(180),np.radians(270),np.radians(360)]
ax=plt.subplot(111,projection='polar')
ax.plot(theta,r)
plt.show()
# stairs
year=range(2005,2020)
plt.step(year,height)
plt.show()
